package cn.com.haopy.yue.ai.db.service.hos.impl;

import cn.com.haopy.yue.ai.db.entity.arisk.AIRiskPapersOptions;
import cn.com.haopy.yue.ai.db.mapper.arisk.AIRiskPapersOptionsMapper;
import cn.com.haopy.yue.ai.db.service.BaseServiceImpl;
import cn.com.haopy.yue.ai.db.service.hos.AIRiskPapersOptionsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @Description: TODO
 * @Author DuTao
 * @Date 2025/3/26 9:13
 */
@Service
public class AIRiskPapersOptionsServiceImpl extends BaseServiceImpl<AIRiskPapersOptionsMapper, AIRiskPapersOptions> implements AIRiskPapersOptionsService {

    @Override
    public AIRiskPapersOptions getOptionsById(Integer paperId, Integer id, Integer sortIndex) {
        QueryWrapper<AIRiskPapersOptions> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(AIRiskPapersOptions::getPaperId, paperId);
        if (Objects.nonNull(sortIndex)) {
            queryWrapper.lambda().eq(AIRiskPapersOptions::getSortIndex, sortIndex);
        }
        if (Objects.nonNull(id)) {
            queryWrapper.lambda().eq(AIRiskPapersOptions::getId, id);
        }
        return super.getOne(queryWrapper);
    }

    @Override
    public List<AIRiskPapersOptions> getByPapersId(Integer id) {
        LambdaQueryWrapper<AIRiskPapersOptions> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AIRiskPapersOptions::getPaperId, id);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public AIRiskPapersOptions getByOptionsPapersId(Integer paperId, Integer topicId) {
        LambdaQueryWrapper<AIRiskPapersOptions> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AIRiskPapersOptions::getPaperId, paperId);
        queryWrapper.eq(AIRiskPapersOptions::getTopicId, topicId);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public AIRiskPapersOptions getByOptionsPapersTopic(Integer paperId, String topicName) {
        LambdaQueryWrapper<AIRiskPapersOptions> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AIRiskPapersOptions::getPaperId, paperId);
        queryWrapper.eq(AIRiskPapersOptions::getTopicName, topicName);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public List<AIRiskPapersOptions> getByOptionsPapersTopicList(Integer paperId, List<String> topicNames) {
        LambdaQueryWrapper<AIRiskPapersOptions> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AIRiskPapersOptions::getPaperId, paperId);
        queryWrapper.in(AIRiskPapersOptions::getTopicName, topicNames);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public Integer paperMaxSortIndex(Integer paperId) {
        return baseMapper.paperMaxSortIndex(paperId);
    }
}
